#############################################/
## R-Script Master - If it ain't broke      ##
## by: Christian Schimpf et al.             ##
## -- Replication Material (Master File)    ##
## Version: Dec. 16, 2020                   ##
## Last updated: August 25, 2021            ##
## R-Version: 4.1.0.                        ##
#############################################/

# This File Runs all R-Scripts related to the paper 
# "If it ain't broke, don't fix it: How the public's economic confidence in the 
# fossil fuel industry reduces support for a clean energy transition" 
# published in Environmental Politics (2021)

# There are three R-Scripts that can be called and run from this Master File
# (provided all paths specified in the files are adjusted accordingly):
# 1. R_Script_Recoding_Schimpfetal2021.R (Is used to generate a dataset
#    based on the original data that is not part of the replication material)
# 2. R_Script_Analyses_Schimpfetal2021.R (Used to run all analyses and produce
#    outputs - tables and figures - shown in main text and appendix).

# To replicate all analyses, save all files in a folder and run the R-Script
# R_Script_Recoding_Schimpfetal2021.R. Note that the results from the Bayesian
# models may vary at the second digit after the comma, due to the MCMC sampling.
# The final run for the results in the paper is saved as a console output in
# .txt file: R_Sessions_ConsoleOutput_Schimpfetal2021.

## Good luck!

#############################################################/
#### >>> Set working directory                           ####
#############################################################/

# clear workspace
rm(list=ls()) 
# set working directory (include path to folder that contains all scripts and data)
setwd("[FOLDER PATH]/Replication Files")

#############################################################/
#### >>> Load Required Packages                          ####
#############################################################/

#install (if necessary) and library required packages; for details on package 
# version, see .txt file: R_Sessions_Info_Schimpfetal2021.txt
library("foreign")
library("likert")
library("ggplot2")
library("reshape2")
library("car")
library("dplyr")
library("MASS")
library("readstata13")
library("brms")
library("rstanarm")
library("bayestestR")
library("ltm")
library("ggridges")
library("gridExtra")
library("bayesplot")
library("tidybayes")
library("psych")
library("viridis")
library("tidyverse")
library("ggeffects")
library("BayesPostEst")

#############################################################/
#### >>> Run scripts                                    ####
#############################################################/

source("./R_Script_Recoding_Schimpfetal2021.R", verbose=F)   ## Recoding original data
source("./R_Script_Analyses_Schimpfetal2021.R", verbose=F)   ## Runs main analyses 

